package com.orangetentacle.bcblackpool;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class MainActivity extends ListActivity {
	
	private RSSHandler _handler = new RSSHandler();
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {    	
    	Log.v("BCBlackpool", "Application Start");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);    
        
        fillResults();
    }
    
    public void fillResults()
    {
    	_handler.updateTweets(this);
    	
    	SimpleAdapter adapter = new SimpleAdapter(this, 
    			_handler._tweets,
    			R.layout.item_row,
    			new String[] { "name", "title" },
    			new int[] { R.id.Username, R.id.Title});
    	
    	setListAdapter(adapter);
    }
    
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
	    super.onListItemClick(l, v, position, id);
	   
	    Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse(_handler._tweets.get(position).url));  
	    startActivity(viewIntent);	    
    }
}